<template>
  <a-modal :width="600" v-model:visible="showSetTimeDialog" title="设置首次入仓时间" title-align="start" :mask-closable="false" :on-before-ok="submitData" :ok-loading="submitLoading" @cancel="closedDialog">
    <div class="flex-c">
      <p style="margin: 30px">时间</p>
      <a-date-picker v-model="timeVal" value-format="YYYY-MM-DD HH:mm:ss" style="width: 200px" />
    </div>
  </a-modal>
</template>
<script lang="ts" setup>
  import { ref } from 'vue'
  import { Message } from '@arco-design/web-vue'
  import { updateGmtWarhousingBatch } from '@/api/publish'

  const emit = defineEmits(['closed', 'success'])
  const props = defineProps({
    isShow: {
      type: Boolean,
      default: false,
    },
    ids: {
      type: Array,
      default: () => [],
    },
  })

  const showSetTimeDialog = ref(props.isShow)
  const timeVal = ref()
  const submitLoading = ref(false)

  // 关闭
  function closedDialog() {
    timeVal.value = null
    showSetTimeDialog.value = false
    emit('closed')
  }
  // 提交
  async function submitData() {
    if (!timeVal.value) {
      Message.error('请选择时间')
      return false
    }
    const res: any = await updateGmtWarhousingBatch({
      gmtWarehousing: timeVal.value,
      idList: props.ids,
    })
    if (res) {
      Message.success('设置成功')
      emit('success')
      closedDialog()
    }
  }
</script>
<style lang="less" scoped></style>
